package com.atech.ebayadmin.common.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.atech.ebayadmin.common.ConstConfig;

public class FileUitl {
	private transient final static Log log = LogFactory.getLog(FileUitl.class);
	public static String saveFile(File file,String realFilePath) throws Exception {
		byte[] buffer = null;
		OutputStream os = null;
		InputStream is = null;
		try{
			is = new FileInputStream(file);
			buffer = new byte[1024];
			File outFile = new File(realFilePath);
			os = new FileOutputStream(outFile);
			
			int length = 0;
			while((length = is.read(buffer))>0){
				os.write(buffer);
			}
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}finally{
			is.close();
			os.close();
		}
		return realFilePath;
	}
	public static void deleteSingleFile(String realFilePath){
		File file=new File(realFilePath);
		if(file.exists()&&!file.isDirectory()){
			boolean result = file.delete();
            if (!result) {
                log.error("删除文件：" + realFilePath + " 失败！");
            }
		}
	}
}
